package com.hnxxxy.jfmgr.controller;

import com.github.pagehelper.PageHelper;
import com.hnxxxy.common.AjaxRtnEntity.AjaxRtnEntity;
import com.hnxxxy.common.annotation.LogAnno;
import com.hnxxxy.common.tools.Help;
import com.hnxxxy.common.tools.TableObj;
import com.hnxxxy.jfmgr.pojo.Jf_detail;
import com.hnxxxy.jfmgr.service.JfUserTestimonialsStatusService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/jf")
@RestController
@Slf4j
public class JfUserTestimonialsStatusController {

    @Autowired
    JfUserTestimonialsStatusService jfUserTestimonialsStatusService;

    @RequestMapping("/f/userTestimonialsStatus")
    @LogAnno(description = "查询奖状上传状态")
    public TableObj findAlUserTestimonialsStatus(TableObj tableObj, Jf_detail jf_detail){
        if (jf_detail.getCertificateName() == ""){
            jf_detail.setCertificateName(null);
        }
        if (jf_detail.getEndTime() == ""){
            jf_detail.setEndTime(null);
        }

        PageHelper.startPage(tableObj.getCurr(), tableObj.getNums());
        List<Jf_detail> list = jfUserTestimonialsStatusService.findAlUserTestimonialsStatus(jf_detail);
        list = GetPhoto(list);
        return Help.getPageTableRtn(tableObj,list);
    }


    @RequestMapping("/d/userTestimonialsStatus")
    @LogAnno(description = "奖状上传状态信息删除",descriptiontype = "deleteUserTestimonialsStatus")
    public AjaxRtnEntity deleteUserTestimonialsStatus(@RequestParam("ids[]") Integer[] ids){
        AjaxRtnEntity ajaxRtnEntity=new AjaxRtnEntity(jfUserTestimonialsStatusService.deleteUserTestimonialsStatus(ids),"删除成功",null);
        return ajaxRtnEntity;
    }

    public List<Jf_detail> GetPhoto(List<Jf_detail> list){
        for (Jf_detail j : list){
            String s = j.getImage();
            int index = s.indexOf(".");
            String right = s.substring(index+4);
            String x = StringUtils.substringBefore(s, right);
            j.setImage(x);
        }
        return list;
    }
}
